package com.ruoyi.od.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.od.domain.OdStatus;
import com.ruoyi.od.service.IOdStatusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 状态Controller
 *
 * @author ruoyi
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/od/status")
public class OdStatusController extends BaseController
{
    @Autowired
    private IOdStatusService odStatusService;

    /**
     * 查询状态列表
     */
    @PreAuthorize("@ss.hasPermi('od:status:list')")
    @GetMapping("/list")
    public TableDataInfo list(OdStatus odStatus)
    {
        startPage();
        List<OdStatus> list = odStatusService.selectOdStatusList(odStatus);
        return getDataTable(list);
    }

    /**
     * 导出状态列表
     */
    @PreAuthorize("@ss.hasPermi('od:status:export')")
    @Log(title = "状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OdStatus odStatus)
    {
        List<OdStatus> list = odStatusService.selectOdStatusList(odStatus);
        ExcelUtil<OdStatus> util = new ExcelUtil<OdStatus>(OdStatus.class);
        util.exportExcel(response, list, "状态数据");
    }

    /**
     * 获取状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('od:status:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(odStatusService.selectOdStatusById(id));
    }

    /**
     * 新增状态
     */
    @PreAuthorize("@ss.hasPermi('od:status:add')")
    @Log(title = "状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OdStatus odStatus)
    {
        return toAjax(odStatusService.insertOdStatus(odStatus));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('od:status:edit')")
    @Log(title = "状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OdStatus odStatus)
    {
        return toAjax(odStatusService.updateOdStatus(odStatus));
    }

    /**
     * 删除状态
     */
    @PreAuthorize("@ss.hasPermi('od:status:remove')")
    @Log(title = "状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(odStatusService.deleteOdStatusByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('od:status:list')")
    @GetMapping("/listall")
    public List<OdStatus> listall(){
        List<OdStatus> list = odStatusService.selectOdStatusList(null);
        return list;
    }
}
